﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CloudFranceTriple.Models;

namespace CloudFranceTriple.WebRole.Areas.Member.Controllers
{
    public class VeteranWorkforceController : Controller
    {
        private cloudfrAboq2RsDMEntities db = new cloudfrAboq2RsDMEntities();

        //
        // GET: /Member/VeteranWorkforce/
        
        [AllowAnonymous]
        [ChildActionOnly]
        public ActionResult ShowWorkForce(int id = 0)
        {
            var veteranwall = db.VeteranWall.Where(vw => vw.VeteranWallPeriodBegin_Id <= id).Where(vw2 => vw2.VeteranWallPeriodEnd_Id >= id).OrderBy(vw3 => vw3.Pseudo).Include(vw5=>vw5.VeteranStatus.Label).Select(vw6=>vw6.Pseudo + " (" + vw6.VeteranStatus.Label + ") ").ToList();
            return PartialView(veteranwall.ToList());
        }

        //
        // GET: /Member/VeteranWorkforce/
        
        [AllowAnonymous]
        public ActionResult Index()
        {
            var veteranwall = db.VeteranWall.OrderBy(vw=>vw.Pseudo).Include(v => v.VeteranStatus);
            return View(veteranwall.ToList());
        }

        //
        // GET: /Member/VeteranWorkforce/Details/5

        [AllowAnonymous]
        public ActionResult Details(int id = 0)
        {
            VeteranWall veteranwall = db.VeteranWall.Find(id);
            if (veteranwall == null)
            {
                return HttpNotFound();
            }
            return View(veteranwall);
        }

        //
        // GET: /Member/VeteranWorkforce/Create

        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult Create()
        {
            ViewBag.VeteranStatus_Id = new SelectList(db.VeteranStatus, "Id", "Label");
            ViewBag.VeteranWallPeriodBegin_Id = new SelectList(db.VeteranWallPeriod, "Id", "VeteranWallPeriodLabel");
            ViewBag.VeteranWallPeriodEnd_Id = new SelectList(db.VeteranWallPeriod, "Id", "VeteranWallPeriodLabel");
            return View();
        }

        //
        // POST: /Member/VeteranWorkforce/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult Create(VeteranWall veteranwall)
        {
            if (ModelState.IsValid)
            {
                veteranwall.Author = User.Identity.Name;
                db.VeteranWall.Add(veteranwall);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.VeteranStatus_Id = new SelectList(db.VeteranStatus, "Id", "Label", veteranwall.VeteranStatus_Id);
            return View(veteranwall);
        }

        //
        // GET: /Member/VeteranWorkforce/Edit/5

        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult Edit(int id = 0)
        {
            VeteranWall veteranwall = db.VeteranWall.Find(id);
            if (veteranwall == null)
            {
                return HttpNotFound();
            }
            ViewBag.VeteranStatus_Id = new SelectList(db.VeteranStatus, "Id", "Label", veteranwall.VeteranStatus_Id);
            ViewBag.VeteranWallPeriodBegin_Id = new SelectList(db.VeteranWallPeriod, "Id", "VeteranWallPeriodLabel", veteranwall.VeteranWallPeriodBegin_Id);
            ViewBag.VeteranWallPeriodEnd_Id = new SelectList(db.VeteranWallPeriod, "Id", "VeteranWallPeriodLabel", veteranwall.VeteranWallPeriodEnd_Id);

            return View(veteranwall);
        }

        //
        // POST: /Member/VeteranWorkforce/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult Edit(VeteranWall veteranwall)
        {
            if (ModelState.IsValid)
            {
                veteranwall.Author = User.Identity.Name;
                db.Entry(veteranwall).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.VeteranStatus_Id = new SelectList(db.VeteranStatus, "Id", "Label", veteranwall.VeteranStatus_Id);
            return View(veteranwall);
        }

        //
        // GET: /Member/VeteranWorkforce/Delete/5

        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult Delete(int id = 0)
        {
            VeteranWall veteranwall = db.VeteranWall.Find(id);
            if (veteranwall == null)
            {
                return HttpNotFound();
            }
            return View(veteranwall);
        }

        //
        // POST: /Member/VeteranWorkforce/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RollVeteranWall")]
        public ActionResult DeleteConfirmed(int id)
        {
            VeteranWall veteranwall = db.VeteranWall.Find(id);
            db.VeteranWall.Remove(veteranwall);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}